import {useListenerStore} from "../stores/listener.ts";
import {storeToRefs} from "pinia";
import {UnlistenFn} from "@tauri-apps/api/event";

export function unListen(){
    let {unListeners} = storeToRefs(useListenerStore());
    if(unListeners.value.length === 0){
        return;
    }
    unListeners.value.forEach(unListenFn => {
        console.log("unListen called:",unListenFn);
        if(unListenFn){
            unListenFn();
            console.log("unListen called");
        }
    });
    unListeners.value = [];
}
export function addListener(listener:UnlistenFn){
    let {unListeners} = storeToRefs(useListenerStore());
    if (listener){
        unListeners.value.push(listener);
    }
}